package com.dzsw.boot.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 同一个类中同时只能触发一个切面，所以调用 firstBiz 的结果如下：
 *
 * ------------------- around firstBiz start
 * ------------------- firstBiz
 * ------------------- secondBiz
 * ------------------- around firstBiz end
 *
 * 仅触发了 firstBiz 的切面，这应该也是切换数据源时在同一个类里无法切换的原因。
 */
@Slf4j
@Aspect
@Component
public class SampleAspect {

    @Around(value = "execution(* com.dzsw.boot.service.IBizService.firstBiz(..))")
    public Object aroundFirstBiz(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info(" ------------------- around firstBiz start");
        Object result = joinPoint.proceed();
        log.info(" ------------------- around firstBiz end");
        return result;
    }

    @Around(value = "execution(* com.dzsw.boot.service.IBizService.secondBiz(..))")
    public Object aroundSecondBiz(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info(" ------------------- around SecondBiz start");
        Object result = joinPoint.proceed();
        log.info(" ------------------- around SecondBiz end");
        return result;
    }
}
